package com.bestcem.xm.member.config;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;

import java.io.File;

/**
 * @author xa.zhang <xa.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2021/7/14 10:56
 * @desc
 */

@Data
@Slf4j
@Configuration
public class FileConfig implements CommandLineRunner {

    private static final String ROOT_FILE_PATH = System.getProperty("user.dir");

    @Value("${app.member.temp.export.dir}")
    private String memberTempFileDir;


    /**
     * 联系人导出数据文件完整路径
     *
     * @return 文件完整路径
     */
    public String getMemberTempFilePath(String fileName) {
        return ROOT_FILE_PATH + File.separator + StrUtil.replace(memberTempFileDir, "/", File.separator) + File.separator + fileName;
    }

    @Override
    public void run(String... args) {
        // 初始化临时目录
        FileUtil.mkdir(getMemberTempFileDir());
    }
}